/* Tables0.do (STATA)
	Tables for variance decomposition of asset prices.
	by Ralph Koijen & Motohiro Yogo */

#delimit ;
clear all;
set more off;
set type double;

cap log close;
log using Tables0, replace;

/* Load data */

u Decomposition0, clear;

/* Construct weights */

egen Tmarket = total(market), missing by(year type);

gen mweight = market/Tmarket;

drop Tmarket;

/* Table: Exchange rate */

qui forval i = 1/9 {;
	reg DLfx`i' DLfx
		if counter_euro!="USA" & type==1 [aw=mweight], robust;

	eststo DLfx`i';
};

/* Output table */

esttab, b(%8.2f) se(%8.2f) plain
	keep(DLfx);

eststo clear;

/* Table: Short-term rate */

qui forval i = 1/9 {;
	reg Dyield`i' Dyield
		if type==1 [aw=mweight], robust;

	eststo Dyield`i';
};

/* Output table */

esttab, b(%8.2f) se(%8.2f) plain
	keep(Dyield);

eststo clear;

/* Table: Long-term yield */

qui forval i = 1/9 {;
	reg Dyield`i' Dyield
		if type==2 [aw=mweight], robust;

	eststo Dyield`i';
};

/* Output table */

esttab, b(%8.2f) se(%8.2f) plain
	keep(Dyield);

eststo clear;

/* Table: Book-to-market equity */

qui forval i = 1/9 {;
	reg DLmb`i' DLmb
		if type==3 [aw=mweight], robust;

	eststo DLmb`i';
};

/* Output table */

esttab, b(%8.2f) se(%8.2f) plain
	keep(DLmb);

eststo clear;

log close;
